package com.smartleanx.module.hrm.controller.admin.employee;

import com.smartleanx.module.hrm.controller.admin.employee.growth.EmployeeGrowthRecordRespVO;
import com.smartleanx.module.hrm.controller.admin.employee.growth.EmployeeGrowthRecordSaveReqVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;

import com.smartleanx.framework.common.pojo.CommonResult;
import com.smartleanx.framework.common.util.object.BeanUtils;

import static com.smartleanx.framework.common.pojo.CommonResult.success;

import com.smartleanx.module.hrm.dal.dataobject.employee.EmployeeGrowthRecordDO;
import com.smartleanx.module.hrm.service.employee.EmployeeGrowthRecordService;

@Tag(name = "管理后台 - 员工成长轨迹")
@RestController
@RequestMapping("/hrm/employee-growth-record")
@Validated
public class EmployeeGrowthRecordController {

    @Resource
    private EmployeeGrowthRecordService employeeGrowthRecordService;

    @PostMapping("/create")
    @Operation(summary = "创建员工成长轨迹")
    @PreAuthorize("@ss.hasAnyPermissions('hrm:employee-growth-record:create','hrm:employee:update')")
    public CommonResult<Long> createEmployeeGrowthRecord(@Valid @RequestBody EmployeeGrowthRecordSaveReqVO createReqVO) {
        return success(employeeGrowthRecordService.createEmployeeGrowthRecord(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新员工成长轨迹")
    @PreAuthorize("@ss.hasAnyPermissions('hrm:employee-growth-record:update','hrm:employee:update')")
    public CommonResult<Boolean> updateEmployeeGrowthRecord(@Valid @RequestBody EmployeeGrowthRecordSaveReqVO updateReqVO) {
        employeeGrowthRecordService.updateEmployeeGrowthRecord(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除员工成长轨迹")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasAnyPermissions('hrm:employee-growth-record:delete','hrm:employee:update')")
    public CommonResult<Boolean> deleteEmployeeGrowthRecord(@RequestParam("id") Long id) {
        employeeGrowthRecordService.deleteEmployeeGrowthRecord(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得员工成长轨迹")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasAnyPermissions('hrm:employee-growth-record:query','hrm:employee:query')")
    public CommonResult<EmployeeGrowthRecordRespVO> getEmployeeGrowthRecord(@RequestParam("id") Long id) {
        EmployeeGrowthRecordDO employeeGrowthRecord = employeeGrowthRecordService.getEmployeeGrowthRecord(id);
        return success(BeanUtils.toBean(employeeGrowthRecord, EmployeeGrowthRecordRespVO.class));
    }

    @GetMapping("/list")
    @Operation(summary = "获得员工成长轨迹列表")
    @Parameter(name = "employeeId", description = "员工编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasAnyPermissions('hrm:employee-growth-record:query','hrm:employee:query')")
    public CommonResult<List<EmployeeGrowthRecordRespVO>> getEmployeeGrowthRecordList(@RequestParam("employeeId") Long employeeId) {
        List<EmployeeGrowthRecordRespVO> result = employeeGrowthRecordService.getEmployeeGrowthRecordList(employeeId);
        return success(result);
    }

}
